<?php
/**
 * 常量节点管理
 */
class ConstantNodeAction extends CommonAction{
    public function add(){
        $list=D('Constant')->order('sort')->select();
        
        $this->assign('constant_list', $list);
        
        $this->display();
    }
    
    public function edit(){
        $id=  intval($_GET['id']);
        $this->assign('vo', D(MODULE_NAME)->where("id={$id}")->find());
        
        $list=D('Constant')->order('sort')->select();
        
        $this->assign('constant_list', $list);
        
        $this->display();
    }
    
    /**
     *获取option子节点列表，自动输出option 
     */
    public function get_node_option(){
        $constant_id=  intval($_POST['constant_id']);
        $selected_id=  intval($_POST['selected_id']);
        
        echo D('Constant')->get_node_option($constant_id,$selected_id);
    }
    
    public function node_view(){
        $constant_id=  intval($_GET['constant_id']);
        $list=D('Constant')->get_all_node($constant_id);
        
        $this->assign('list', $list);
        $this->display();
    }
    
}

/**
 *根据constant_id获取常量的标题
 * @param int $id 常量ID
 * 
 * @return string 常量标题 
 */
function get_constant_title($id){
    $id=  intval($id);
    return D('Constant')->where("id={$id}")->getField('constant_title');
}

/**
 *根据parent id获取该节点名称 
 */
function get_parent_name($parent_id){
    $parent_id=  intval($parent_id);
    return $parent_id==0?'顶级节点':D(MODULE_NAME)->where("id={$parent_id}")->getField('name');
}

?>
